package com.kaili.controller.common.v1;

import com.baomidou.mybatisplus.plugins.Page;
import com.kaili.common.exception.BaseExcept;
import com.kaili.db.service.IHsBasicSeqService;
import com.kaili.db.service.IHsEwbsDispatchService;
import com.kaili.except.ResponseStatus;
import com.kaili.pojo.dto.dispatch.DispatchAddDTO;
import com.kaili.pojo.dto.dispatch.DispatchQueryDTO;
import com.kaili.pojo.vo.DispatchVO;
import com.kaili.pojo.vo.EwbDispatchVO;
import com.kaili.version.ApiVersion;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @AUTHOR pengdongxu.
 * @Date: 18-5-25 上午9:13.
 * @COPYRIGHT 杭州凯立
 */

@ApiVersion(1)
@RequestMapping("/{api_version}")
@RestController("arriveSendControllerC")
@Validated
@Api(tags = "[PDA和WEB端通用]到件派送", description = "[通用]到件送货相关API")
public class ArriveSendController {

    @Autowired
    private IHsBasicSeqService basicSeqService;
    @Autowired
    private IHsEwbsDispatchService dispatchService;

    @ApiOperation(value = "获取送货单号")
    @GetMapping("/c/dispatchs/sendCode")
    public String setSendCode(){
        return basicSeqService.seqByTypeWithType("SH");
    }

    @ApiOperation(value = "获取送货信息")
    @GetMapping("/c/dispatchs")
    public Page<DispatchVO> queryDispatchEwbList(@Validated @ModelAttribute DispatchQueryDTO req){
        if (req.getCur()!= null && req.getPageSize() !=null){
            Map<Object, Object> search = new HashMap<>();
            search.putAll(new org.apache.commons.beanutils.BeanMap(req));
            Page<DispatchVO> page = new Page<>(req.getCur(),req.getPageSize());
            page = dispatchService.queryDispatchEwbList(page,search);
            return page;
        }
        throw new BaseExcept(ResponseStatus.DISPATCH_QUERY_ERR);
    }

    @ApiOperation(value = "新增派送")
    @PostMapping("/c/dispatchs/bat")
    public Map<String, String> addDispatch(@Validated @RequestBody DispatchAddDTO dispatchAddDTO){
        return dispatchService.addDispatchBS(dispatchAddDTO);
    }
}
